4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
11 // You must not remove this notice, or any other, from this software.
16 namespace Microsoft
.JScript
{
19 using System
.Globalization
;
20 using System
.Reflection
;
22 internal sealed class JSClosureField
: JSVariableField
{
23 internal FieldInfo field
; //Used to indicate that the field is accessed from a nested (static) function.
25 internal JSClosureField(FieldInfo field
)
26 : base(field
.Name
, null, field
.Attributes
|FieldAttributes
.Static
){ //Fool the analysis code to OK calls to this method from static code
27 if (field
is JSFieldInfo
) field
= ((JSFieldInfo
)field
).field
;
31 public override Type DeclaringType
{
33 return this.field
.DeclaringType
;
37 public override Type FieldType
{
39 return this.field
.FieldType
;
43 internal override IReflect
GetInferredType(JSField inference_target
){
44 if (this.field
is JSMemberField
)
45 return ((JSMemberField
)this.field
).GetInferredType(inference_target
);
47 return this.field
.FieldType
;
50 internal override Object
GetMetaData(){
51 if (this.field
is JSField
)
52 return ((JSField
)this.field
).GetMetaData();
57 public override Object
GetValue(Object obj
){
58 if (obj
is StackFrame
)
59 return this.field
.GetValue(((StackFrame
)((StackFrame
)obj
).engine
.ScriptObjectStackTop()).closureInstance
);
60 throw new JScriptException(JSError
.InternalError
); //should never happen
63 public override void SetValue(Object obj
, Object
value, BindingFlags invokeAttr
, Binder binder
, CultureInfo locale
){
64 if (obj
is StackFrame
){
65 this.field
.SetValue(((StackFrame
)((StackFrame
)obj
).engine
.ScriptObjectStackTop()).closureInstance
, value, invokeAttr
, binder
, locale
);
68 throw new JScriptException(JSError
.InternalError
); //should never happen